package com.xxxx.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created By ShaoXikai on 2022/7/21
 */
@Component
@Aspect
public class Case {

    @Pointcut("execution(* com.xxxx.service.*Service.*(..))")
    private void serviceAsj(){}
    @Pointcut("execution(* com.xxxx.dao.*Dao.*(..))")
    private void daoAsj(){}

    // @Around("serviceAsj()")
    // public Object serviceRunnerTime(ProceedingJoinPoint joinPoint) {
    //
    //     System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(new Date()));
    //     Object proceed = new Object();
    //     try {
    //         proceed = joinPoint.proceed();
    //     } catch (Throwable e) {
    //         e.printStackTrace();
    //     }
    //     System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(new Date()));
    //     return proceed;
    // }
    //
    @Before("daoAsj()")
    public void before(){
        System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(new Date()));
    }

    @After("daoAsj()")
    public void after(){
        System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(new Date()));
    }

}
